/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ronin.model;


import com.ronin.model.constant.DurumEnum;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author esimsek
 */
@Entity
@Table(name = "urun")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Urun.findAll", query = "SELECT u FROM Urun u"),
    @NamedQuery(name = "Urun.findById", query = "SELECT u FROM Urun u WHERE u.id = :id"),
    @NamedQuery(name = "Urun.findBySubeId", query = "SELECT u FROM Urun u WHERE u.sube.id = :subeId"),
    @NamedQuery(name = "Urun.findByAd", query = "SELECT u FROM Urun u WHERE u.ad = :ad"),
    @NamedQuery(name = "Urun.findByFiyat", query = "SELECT u FROM Urun u WHERE u.fiyat = :fiyat")})
public class Urun implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @JoinColumn(name = "sube_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Sube sube;
    @Basic(optional = false)
    @Column(name = "ad")
    private String ad;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Basic(optional = false)
    @Column(name = "fiyat",precision = 2)
    private BigDecimal fiyat;
    @OneToMany(cascade = CascadeType.REFRESH, mappedBy = "urun")
    private List<MusteriUrun> musteriUrunList;
    @JoinColumn(name = "urun_kategori_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private UrunKategori urunKategori;
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "durum_id")
    private DurumEnum durum;
    
    @Version
    private int versiyon;


    public Urun() {
    }

    public Urun(Long id) {
        this.id = id;
    }

    public Urun(Long id, Sube sube, String ad, BigDecimal fiyat, DurumEnum durum) {
        this.id = id;
        this.sube = sube;
        this.ad = ad;
        this.fiyat = fiyat;
        this.durum = durum;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Sube getSube() {
        return sube;
    }

    public void setSube(Sube sube) {
        this.sube = sube;
    }

    public String getAd() {
        return ad;
    }

    public void setAd(String ad) {
        this.ad = ad;
    }

    public BigDecimal getFiyat() {
        return fiyat;
    }

    public void setFiyat(BigDecimal fiyat) {
        this.fiyat = fiyat;
    }

    @XmlTransient
    public List<MusteriUrun> getMusteriUrunList() {
        return musteriUrunList;
    }

    public void setMusteriUrunList(List<MusteriUrun> musteriUrunList) {
        this.musteriUrunList = musteriUrunList;
    }

    public UrunKategori getUrunKategori() {
        return urunKategori;
    }

    public void setUrunKategori(UrunKategori urunKategori) {
        this.urunKategori = urunKategori;
    }

    public DurumEnum getDurum() {
        return durum;
    }

    public void setDurum(DurumEnum durum) {
        this.durum = durum;
    }

    public int getVersiyon() {
        return versiyon;
    }

    public void setVersiyon(int versiyon) {
        this.versiyon = versiyon;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Urun)) {
            return false;
        }
        Urun other = (Urun) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ronin.model.Urun[ id=" + id + " ]";
    }
    
}
